//
//  MineObligationsController.m
//  JewelryStore
//
//  Created by wsk on 17/1/12.
//  Copyright © 2017年 com. All rights reserved.
//

#import "MineObligationsController.h"
#import "MineNoOrderCell.h"
#import "MineNoOrderHeaderCell.h"
@interface MineObligationsController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation MineObligationsController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"顶部返回-点击"] style:UIBarButtonItemStyleDone target:self action:@selector(goBack)];
    self.navigationItem.leftBarButtonItem  = item;
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"m_xiaoxi"] style:UIBarButtonItemStyleDone target:self action:@selector(newsAction)];
    self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.collectionView];

}

#pragma mark --delegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }
    else
        return 5;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        MineNoOrderHeaderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MineNoOrderHeaderCell class]) forIndexPath:indexPath];
        return cell;
    }
    else {
        MineNoOrderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MineNoOrderCell class]) forIndexPath:indexPath];
        return cell;
    }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return CGSizeMake(SCREEN_WIDTH, 250);
    }else {
        return CGSizeMake(SCREEN_WIDTH/2 - 2, SCREEN_WIDTH / 2 - 10 - 2 * 30 + 100);
    }
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark --actions
- (void)goBack {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)newsAction {
    
}

#pragma mark --getters
- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 5;
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([MineNoOrderCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([MineNoOrderCell class])];
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([MineNoOrderHeaderCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([MineNoOrderHeaderCell class])];
    }
    return _collectionView;
}

@end
